<?php
ArrowController::importModel("smarty.SmartyCompiler");
class ArrowTableRowTemplate extends ArrowTagContainer{
	
	private $transport;
	private $triggerColumn;
	
	public function configure(){
		$this->addProperties(array(
			"type" => "rowTemplate", //rowExtensionTemplate, searchTemplate
			"transport" => false,
			"triggerColumn" => false
		));
		$this->setRequiredParent("ArrowTable");
		$this->setContentCodeKept(true);
		$this->setDisplay(false);
		$this->setParseContent(true);
		//$this->setLazyInit(true);
	}
	
	public function init(){
		parent::init();
		$this->transport = $this->getProperty("transport");
		$this->triggerColumn = $this->getProperty("triggerColumn");
		$this->type = $this->getProperty("type");
	}
	
	public function generateTemplate(){
		$this->setDisplay(true);
		$str =  $this->generateBlockStart1();
		$this->setDisplay(false);
		return $str;
	}
	
	public function generateBlockStart(){
		
		if($this->type=="rowExtensionTemplate"){
			//$this->setDisplay(true);
			return $this->generateBlockStart1();
		}
		
	}
	
	public function generateBlockStart1(){
		
		$model = $this->getState("model");
		
		$compiler = new SmartyCompiler($this->getContentCode(),  ArrowView::getCurrentView()->ts);
		if($model){
			$class = ArrowModel::getModelClass( $model );
			$key = $this->getState("key");
			$context = call_user_func(array( $class, "getByKey" ), $key, $class );
			$this->setContext( "rowTemplate".$key, $context);
			foreach($this->getAllChildren() as $child){
				$child->setProperty("contextId", "rowTemplate".$key);
			}	
			
			$compiler->assign("context", $context);
		}else 
			$compiler->assign("context", null);
		$compiler->assign("transport", $this->transport);
		return $compiler->getResult(array());
	}
	
	public function generateBlockEnd(){
		return "";
	}
	
	public function getTriggerColumn(){
		return $this->triggerColumn;
	}
	
}
?>
